<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.sictiy.common.db.mapper.{{ meta.java_name }}Mapper">
    {% for select in meta.selects -%}
    <select id="queryBy{{ select.up_name() }}" resultType="com.sictiy.common.db.pojo.{{ meta.java_name }}Info">
        select * from {{ meta.table }} where {{ select.name }} = #{{ '{' }}{{ select.name }}{{ '}' }}
    </select>
    {% endfor %}
    {% for select in meta.list_selects -%}
        <select id="queryListBy{{ select.up_name() }}" resultType="com.sictiy.common.db.pojo.{{ meta.java_name }}Info">
            select * from {{ meta.table }} where {{ select.name }} = #{{ '{' }}{{ select.name }}{{ '}' }}
        </select>
    {% endfor %}
    <select id="queryAll" resultType="com.sictiy.common.db.pojo.{{ meta.java_name }}Info">
        select * from {{ meta.table }}
    </select>

    <insert id="insert" useGeneratedKeys="true" keyColumn="{{ meta.key.name }}" keyProperty="{{ meta.key.name }}"
            parameterType="com.sictiy.common.db.pojo.{{ meta.java_name }}Info">
        INSERT INTO {{ meta.table }} ({% for field in meta.fields -%}
            {% if loop.last %}
                {{ field.name }}
            {% else %}
                {{ field.name }},
            {%- endif %}
        {%- endfor %})
        VALUES ({% for field in meta.fields -%}
            {% if loop.last %}
                #{{ '{' }}{{ field.name }}{{ '}' }}
            {% else %}
                #{{ '{' }}{{ field.name }}{{ '}' }},
            {%- endif %}
        {%- endfor %});
    </insert>

    <update id="update" parameterType="com.sictiy.common.db.pojo.{{ meta.java_name }}Info">
        UPDATE {{ meta.table }}
        <trim prefix="set" suffixOverrides=",">
            {%- for field in meta.fields -%}
                {% if not field.name == meta.key.name %}
                    <if test="{{ field.name }}!=null">{{ field.name }} = #{{ '{' }}{{ field.name }}{{ '}' }},</if>
                {%- endif %}
            {%- endfor %}
        </trim>
        WHERE
        ({{ meta.key.name }} = #{{ '{' }}{{ meta.key.name }}{{ '}' }});
    </update>
</mapper>